package com.lw.sbdemo2.mapper;

import com.lw.sbdemo2.common.base.BaseMapper;
import com.lw.sbdemo2.entity.TkTeacherClassStudent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>标题: 教师班级学生表服务 - 数据交互层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2019-4-14
 */
@Mapper
public interface TkTeacherClassStudentMapper extends BaseMapper<TkTeacherClassStudent> {

	/**
     * 分页获取教师班级学生表列表
     *
     * @param query 搜索关键词
	 * @param tkTeacherClassStudent 查询实体
     * @return 用户列表
     */
    List<TkTeacherClassStudent> findListPage(@Param("query") String query, @Param("model") TkTeacherClassStudent tkTeacherClassStudent);

	/**
	 * 分页获取教师班级学生表列表
	 *
	 * @param tkTeacherClassStudent 查询实体
	 * @return 用户列表
	 */
	Integer getStudentCount(TkTeacherClassStudent tkTeacherClassStudent);

	@Select("select t.*,a.USER_NAME from tk_teacher_class_student t, tk_user_info a where a.TEACHER_ID = t.DATA_ID  and t.DATA_ID =" +
			" #{classId} and a.USER_ID NOT" +
			" IN (select d" +
			".user_id" +
			" " +
			"from tk_user_answer_exam_record d, tk_user_info a where  a.USER_ID = d.USER_ID and d.END_TIME is not null and d.EXAM_ID = #{examId} and a.TEACHER_ID = #{classId})")
	List<TkTeacherClassStudent> noAnswer(@Param("examId") String examId, @Param("classId") String classId);


	/**
	 * 根据微信ID获取用户信息
	 */
	@Update("update tk_teacher_class_student t set t.IS_DEFAULT = '0' where t.TEACHER_ID = #{teacherId}")
	void updateDefault(@Param("teacherId") String teacherId);
}
